package com.yumeng.common.auth;

import com.yumeng.common.exception.YumengException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @author wxd
 * @date 2025/2/25 21:54
 */
@Component
public class BaseAuthHelper {

    private static AbsAuthHelper absAuthHelper;
    @Autowired
    public void setAbsAuthHelper(AbsAuthHelper absAuthHelper) {
        BaseAuthHelper.absAuthHelper = absAuthHelper;
    }

    /**
     * 获取当前认证信息
     *
     * @return
     */
    public static BaseAuthInfo getCurrAuthInfo(){
        return BaseAuthHelper.absAuthHelper.doGetCurrAuthInfo(true);
    }

    /**
     * 获取当前认证信息
     *
     * @return
     */
    public static BaseAuthInfo getCurrAuthInfo(boolean strict){
        BaseAuthInfo authInfo = BaseAuthHelper.absAuthHelper.doGetCurrAuthInfo(strict);
        if (authInfo == null){
            throw new YumengException("当前用户信息获取失败");
        }
        return authInfo;
    }

    public static void printAuthFrameInfo(ConfigurableApplicationContext context){
        BaseAuthHelper.absAuthHelper.printAuthFrameInfo(context);
    }

    /**
     * 异常是否需要直接抛出
     *
     * @param ex
     * @return
     */
    public static boolean needThrowException(Exception ex){
        return BaseAuthHelper.absAuthHelper.needThrowException(ex);
    }

}
